package com.yunliuchain.examination.exam.web.controller.admin;
import com.yunliuchain.examination.exam.entity.Paper;
import com.yunliuchain.examination.exam.service.PaperService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSON;
import com.yunliuchain.examination.common.req.QueryReq;
import com.yunliuchain.examination.common.controller.CommonController;
import com.yunliuchain.examination.common.res.ApiResult;
import com.yunliuchain.examination.common.res.PageList;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
        import io.swagger.annotations.Api;
import java.util.HashMap;

/**<p>Title:试卷表 控制器 </p>
 * <p>Description: </p>
 * <p>作者：zzc</p>
 * <p>日期：2018-05-22 11:12:13</p>
 * <p>版本：1.0</p>
 */
@RestController
@RequestMapping("/yunbandan/admin/exam/paper")
@Api(description = "试卷接口")
public class PaperController extends CommonController {
    private final Logger logger = Logger.getLogger(getClass());

    @Autowired
    private PaperService paperService;


    /**
     * 查询单条记录
     * @param id
     * @return ApiResult
     */
    @Override
    public ApiResult get(@PathVariable Long id) {
        return paperService.get(id);
    }


    /**
     * 保存
     * @param json
     * @return ApiResult
     */
    @Override
    public ApiResult save(@RequestBody String json) {
        return paperService.save(JSON.parseObject(json, Paper.class));
    }


    /**
     * 更新
     * @param json
     * @return ApiResult
     */
    @Override
    public ApiResult update(@RequestBody String json) {
       return paperService.update(JSON.parseObject(json, Paper.class));
    }


    /**
     * 批量删除
     * @param json
     * @return ApiResult
     */
    @Override
    public ApiResult delByIds(@RequestBody String json) {
       return  paperService.delByIds(JSONArray.parseArray(json,Long.class));
    }

    /**
     * 分页列表查询
     * @param json
     * @return ApiResult
     */
    @Override
    public ApiResult pageList(@RequestBody(required = false) String json) {
        logger.debug("paper pageList: "+ json);
        QueryReq queryReq = buildQueryReq(json);
        PageList<Paper> pageList = paperService.pageList(queryReq);
        return ApiResult.success(pageList);
    }
}
